/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.struts.controleur;

import com.myapp.struts.modele.QueryBD;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author jackson
 */
public class ConnexionAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        HttpSession session = request.getSession();
        ConnexionForm cf = (ConnexionForm) form;
        String num = cf.getNum();
        String mdp = cf.getPassword();
        String statut = cf.getStatut();
        QueryBD bd = new QueryBD();
        if (statut.equals("Prof")) {
            if (bd.ConnexionEnseignant(num, mdp)) {
                session.setAttribute("bd", bd);
                return mapping.findForward("enseignant");
            } else {
                return mapping.findForward("index");
            }
        } else {
            if (bd.ConnexionEtudiant(num, mdp)) {
                session.setAttribute("bd", bd);
                return mapping.findForward("etudiant");
            } else {
                return mapping.findForward("index");
            }
        }
    }
    
}
